import org.switchyard.component.bpm.task.*;
SwitchYard provides an implementation-agnostic API is available which allows you to programmatically interact with Human Tasks. The API provides mechanisms to:
Start and stop a Task Server.
Connect a Task Client to a Task Server.
Use the Task Client to:
Get assigned Tasks.
Claim Tasks.
Start Tasks.
Get/Set Task Content.
Complete Tasks.
Inspect Tasks for their id, name, status and parent process instance id.
The API is a very thin wrapper around jBPM, and doesn't cover everything you can do with jBPM. As people require more functionality to be exposed, we will consider adding those hooks.
The purpose behind providing a SwitchYard-specific Task API is two-fold:
Make it easy for web application developers to access and manage tasks in the BPM runtime. The point here is that people are going to create their own web apps that interact with BPM tasks.
Provide an abstraction over the implementation. Using this API developers only have to worry about SwitchYard interfaces rather than depending upon another library. It also allows us to integrate with another BPM runtime in the future if we so choose (although the chances of that are slim for the foreseeable future).
For all examples below, please assume the following import:
import org.switchyard.component.bpm.task.*;
Starting and stopping a TaskServer can be done easily:
TaskServer server = TaskService.instance().newTaskServer(); server.setHost("localhost").setPort(9123).start(); // task clients can connect server.stop();
Connecting and disconnecting a TaskClient is just as easy:
TaskClient client = TaskService.instance().newTaskClient(); client.setHost("localhost").setPort(9123).connect(); // work with the client client.disconnect();
If you are familiar with jBPM 5, the method signatures below should seem somewhat familiar to you, as jBPM 5 is used under-the-hood. There are minor differences such as Long wrappers instead of long primitives for task ids, no need to specify a BlockingResponseHandler for client interaction, etc.
TaskClient client = // see above String userId = "david"; List<String> groupIds = Arrays.asList(new String[]{"users"}); List<Task> tasks = client.getTasksAssignedAsPotentialOwner(userId, groupIds); for (Task task : tasks) { if (TaskStatus.COMPLETED.equals(task.getStatus())) { continue; } Long taskId = task.getId(); client.claim(taskId, userId, groupIds); client.start(taskId, userId); client.complete(taskId, userId, null); }
Application-specific objects are supported, and stores as name/value variables in a map within a TaskContent. Because this data can be large, it is not pulled when initially querying for Tasks. You have to make a separate call to the TaskClient to get the TaskContent.
TaskClient client = // see above String userId = // see above Task task = // see above TaskContent content = client.getTaskContent(task.getTaskContentId()); Map<String, Object> data = content.getVariableMap(); MyAppObject mao = (MyAppObject)data.get("myAppVariable"); // use or mutate mao client.complete(task.getId(), userId, content);
To see the Task API in action, please refer to the following quickstart demos in the SwitchYard distribution:
A video of the Help Desk Web App is available on YouTube.